package com.digital.smartgrow.controller.business;

import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.business.UpPubilcityPageDTO;
import com.digital.smartgrow.entity.business.UpPubilcity;
import com.digital.smartgrow.service.business.UpPubilcityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 晋升公示 前端控制器
 * </p>
 *
 * @author sunyuechao
 * @since 2022-08-31
 */
@Api(tags = "晋升公示")
@RestController
@RequestMapping("${context.prefix}/syc/upPubilcity")
public class UpPubilcityController {

    @Autowired
    private UpPubilcityService upPubilcityService;

    @ApiOperation(value = "晋升公示-分页查询")
    @PostMapping("/list")
    public Object getListByPage(@RequestBody UpPubilcityPageDTO upPubilcityPageDTO){
        return upPubilcityService.getListByPage(upPubilcityPageDTO);
    }

    @ApiOperation(value = "晋升公示-详情")
    @GetMapping("/{id}")
    public Object getInfo(@PathVariable Integer id){
        if (id == null) return Result.fail("id不能为空");
        return upPubilcityService.getInfo(id);
    }

    @ApiOperation(value = "晋升公示-删除")
    @DeleteMapping("/{id}")
    public Object removeById(@PathVariable Integer id){
      if (id == null) return Result.fail("id不能为空");
      return upPubilcityService.removeById(id);
    }
    @ApiOperation(value = "晋升公示-新增")
    @PostMapping()
    public Object add( @RequestBody UpPubilcity upPubilcity){
       return upPubilcityService.save(upPubilcity);
    }

    @ApiOperation(value = "晋升公示-编辑")
    @PutMapping()
    public Object edit(@RequestBody UpPubilcity upPubilcity){
    if (upPubilcity==null||upPubilcity.getId() == null)
       return Result.fail("id不能为空");
       return upPubilcityService.updateById(upPubilcity);
    }
}
